
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>商品管理</title>
    {include file='header'}
</head>
<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a>首页</a>
            <a>文章管理</a>
            <a><cite>列表</cite></a>
        </span>
        <div style="float: right;">            
            <a href="javascript:;" onclick="xadmin.open('添加','{:url('modify')}?parent_id={$category_id}')"><button class="layui-btn"><i class="layui-icon">&#xe61f;</i>添加</button></a>
            <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon">&#xe640;</i>批量删除</button>
            <a class="layui-btn layui-btn-small" href="javascript:location.replace(location.href);" title="刷新">
                <i class="layui-icon layui-icon-refresh-1"></i></a>
        </div>
    </div>
    <div class="x-body">
            <form class="layui-form">
                <div class="layui-input-inline layui-show-xs-block">
                    <input class="layui-input" placeholder="关键词" name="keyword"></div>
                <div class="layui-input-inline layui-show-xs-block">
                    <button class="layui-btn"  lay-submit="" lay-filter="sreach">搜索</button>
                </div>
            </form>
        <table class="layui-table">
            <thead>
                <tr>
                    <th style="width: 25px;">
                        <div class="layui-unselect header layui-form-checkbox layui-form-checkbox-header"  data-id='0'lay-skin="primary"><i class="layui-icon">&#xe605;</i></div>
                    </th>
                    <th style="width: 80px;">分类名称</th>
                    <th>标题</th>
                    <th style="width: 150px; text-align: center;">发布时间</th>
                    <th style="width: 100px;text-align: center;">操作</th>
                </tr>
            </thead>
            <tbody>
                {foreach $data_list as $vo}
                <tr>
                    <td style="width: 25px;">
                        <div class="layui-unselect layui-form-checkbox layui-form-checkbox-item" lay-skin="primary" data-id='{$vo.id}'><i class="layui-icon">&#xe605;</i></div>
                    </td>
                    <td>{$vo.category_name}</td>
                    <td>{$vo.title}</td>          
                    <td>{$vo.add_time|date='Y-m-d'}</td>
                    <td class="td-manage" style="width:120px;">
                        <a class="layui-btn layui-btn-xs" onclick="xadmin.open('编辑','{:url('modify',['id'=>$vo.id])}')">编辑</a>
                        <a class="layui-btn layui-btn-danger layui-btn-xs" onclick="remove({$vo.id})">删 除</a>                        
                    </td>
                </tr>{/foreach}             
            </tbody>
        </table>
        {$page|raw}
    </div>
    <script>
    $(function(){
        $(".layui-form-checkbox-item").click(function(){
            $(this).toggleClass('layui-form-checked')
        })
        $(".layui-form-checkbox-header").click(function(){
            $(this).toggleClass('layui-form-checked')
            if($(this).hasClass('layui-form-checked'))
            {
                $(".layui-form-checkbox-item").each(function(){
                    if(!$(this).hasClass('layui-form-checked'))
                    {
                        $(this).addClass('layui-form-checked')
                    }
                })
            }
            else
            {
                $(".layui-form-checkbox-item").each(function(){
                    if($(this).hasClass('layui-form-checked'))
                    {
                        $(this).removeClass('layui-form-checked')
                    }
                })
            }
        })
    })
    function set_status(id,status){
        $.post("{:url('status')}",{id:id,status:status},function(res){
        if(res.code==1)
        {
          layer.msg('操作成功',{icon:1,time:1000},function(){
            location.reload();
          })
        }
        else
        {
          layer.msg('操作失败');
        }
      },'json');
    }
    function remove(id)
    {
        if(confirm('确定要删除数据吗?'))
        {
        $.post("{:url('remove')}",{id:id},function(res){
            if(res.code==1)
            {
            layer.msg('删除成功',{icon:1,time:1000},function(){
                location.reload();
            })
            }
            else
            {
            layer.msg('操作失败');
            }
        })
        }
    }
    /*用户-批量删除*/
    function delAll(argument) {
        var ids = tableCheck.getData().toString();
        if (ids == "") {
            layer.msg('请选择要删除的数据！', { icon: 0 });
            return false;
        }
       
        layer.confirm('确认要删除所选吗？', function (index) {
            layer.close(index);
            //捉到所有被选中的，发异步进行删除
            $.ajax({
                type: "POST",
                url: "{:url('removeall')}",
                data: { "ids": ids },
                datatype: "json",
                success: function (res, textStatus) {
                    console.log(res)
                    if (res.code == 1) {
                        layer.msg(res.msg, { icon: 1, time: 1000 },function(){
                            location.reload();
                        });
                        //$(".layui-form-checked").not('.header').parents('tr').remove();
                        
                    }
                    else {
                        layer.alert(res.msg, { icon: 5 });
                        return false;
                    }
                },
                error: function (e) {
                    layer.alert('系统出现错误,请检查系统！', { icon: 2 });//0感叹号  1打勾  2打叉  3问号  4锁头  5难过  6笑脸
                    return false;
                }
            });
        });
    }
    </script>
</body>
</html>